package chapter7classloader;

public class P77 {
    static class Test{
        static {
            if (true){
                System.out.println(Thread.currentThread().getName()+"进入了");
                int x = 0;
                while (x<10){
                    try {
                        Thread.sleep(50);
                        x++;
                        System.out.println(Thread.currentThread().getName()+" 休眠");
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }

    public static void main(String[] args) {

        //多个线程同时初始化，会等待最开始初始化完成的线程初始化完了之后，才会使用初始化完成的类，static中的代码有且初始化一次
        Runnable runnable = () -> {
            System.out.println(Thread.currentThread().getName()+" 执行");
            Test test = new Test();
            System.out.println(Thread.currentThread().getName()+" 结束");
        };
        Thread thread1 = new Thread(runnable);
        Thread thread2 = new Thread(runnable);
        thread1.start();
        thread2.start();
    }
}
